﻿using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using EasyLibrary.AR;
using EasyLibrary.AR.Classes;

namespace EasyFrota_Mobile
{
    public partial class Localizacao : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
              
                IList ViaturaTipoList = new ArrayList();
                var vt = new ViaturaTipo();
                ViaturaTipoList = vt.LoadAll();
                DropDownAdd(ViaturaTipoList);
                IList ViaturaList = new ArrayList();
                var v = new Viatura();
                int id = Convert.ToInt32(Session["IDUtilizadores"]);
                ViaturaList = v.LoadAll(id);
                LoadTabela(ViaturaList);

            
            }
            HtmlGenericControl body = (HtmlGenericControl)Page.Master.FindControl("mobileBody");
            body.Attributes.Add("onload", "initialize();");
        }

        private void DropDownAdd(IList viaturaTipoList)
        {
            foreach (ViaturaTipo viaTipo in viaturaTipoList)
            {
                dropDownCategorias.Items.Add(new ListItem(viaTipo.TipoViatura, viaTipo.Id.ToString()));
            }
            dropDownCategorias.Items.Insert(0, "Todos");
        }

        private void LoadTabela(IList viaturaList)
        {
          
                int count = 0;
                foreach (Viatura via in viaturaList)
                {
                    if (count == 0)
                    {
                        LiteralTabelaCarros.Text += "<tr>";
                    }

                    LiteralTabelaCarros.Text += "<td>" + via.Matricula + "</td>";
                    LiteralTabelaCarros.Text += "<td><input type=checkbox class=custom name=vID value=\"" + via.Idviatura + "\" onClick='seleciona(this)' id=\"vID_" + via.Idviatura + "\" >" +
                                                "<label for=vID_"+via.Idviatura+"> </label>  </td>";

                    count++;
               

                    if (count != 2)
                    {
                        continue;
                    }
                    LiteralTabelaCarros.Text += "</tr>";
                    count = 0;
                }
            
           
        }

        protected void dropDownCategorias_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}